/**
 *
 * @param param
 * @returns
 */
export function getFeeInfo(input, param) {
//   console.log("input:", input);

  // 提取费用类型
  const feeType = input.split(":")[0];

  // 提取时间段和费用
  const costs = extractTimeSegmentsAndCosts(input);

  if (param === "name") {
    return feeType; // 返回费用类型
  }

  if (param === "time" || param === "fee" || param === "arr") {
    const currentCostInfo = getCurrentCostForCurrentTime(costs);

    if (param === "arr") {
      return costs;
    }
    if (param === "time") {
      return currentCostInfo ? currentCostInfo.timeRange : null; // 返回时间段
    }

    if (param === "fee") {
      return currentCostInfo ? currentCostInfo.cost : null; // 返回费用
    }
  }

  function extractTimeSegmentsAndCosts(input) {
    const result = [];
    const regex = /(\d{2}:\d{2}~\d{2}:\d{2}):([\d.]+)/g;
    let match;

    while ((match = regex.exec(input)) !== null) {
      const timeRange = match[1];
      const cost = parseFloat(match[2]);
      result.push({ timeRange, cost });
    }

    return result;
  }

  function getCurrentCostForCurrentTime(costs) {
    const now = new Date();
    const currentHour = String(now.getHours()).padStart(2, "0");
    const currentMinute = String(now.getMinutes()).padStart(2, "0");
    const currentTime = `${currentHour}:${currentMinute}`;

    for (const { timeRange, cost } of costs) {
      const [start, end] = timeRange.split("~");
      if (currentTime >= start && currentTime < end) {
        return { timeRange, cost };
      }
    }

    return null;
  }

  return null; // 如果参数不匹配
}
